<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml" lang="en">

<head th:replace="~{/admin/_fragments:: head(~{::title})}">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title th:if="${blog.id} != null" th:text="${blog.title}">文章输入</title>
    <title th:if="${blog.id} == null">文章输入</title>


    <link rel="stylesheet" href="../../static/css/me.css" th:href="@{/css/me.css}">
    <link rel="stylesheet" href="../../static/semantics-dist/semantic.min.css" th:href="@{/semantics-dist/semantic.min.css}">
    <script src="../../static/js/jquery-3.7.1.min.js" th:src="@{/js/jquery-3.7.1.min.js}" ></script>
<!--    <link rel="stylesheet" href="/static/lib/editormd-master/lib/codemirror/codemirror.min.css" th:href="@{lib/editormd-master/lib/codemirror/codemirror.min.css}">-->
    <link rel="stylesheet" href="../../static/lib/editormd-master/css/editormd.min.css" th:href="@{/lib/editormd-master/css/editormd.min.css}">
<!--    <script src="../../static/lib/editormd-master/lib/codemirror/codemirror.min.js" th:src="@{lib/editormd-master/lib/codemirror/codemirror.min.js}"> </script>-->
    <script src="../../static/lib/editormd-master/editormd.min.js" th:src="@{/lib/editormd-master/editormd.min.js}"> </script>
<!--    我也搞不懂弱智索引-->
    <script src="../../static/semantics-dist/semantic.min.js" th:src="@{/semantics-dist/semantic.min.js}" ></script>
</head>
<body>

<nav th:replace="~{admin/_fragments :: menu(1)}"  class="ui   attached segment m-padded-tb-mini m-shadow-small" >
    <div class="ui container"  >
        <div class="ui   secondary stackable menu">
            <a href="#" th:href="@{/admin/blogs}">
                <h3 class="ui  teal header item" ><i class="ui clipboard outline icon"></i>文章管理</h3></a>
          <div class="right m-mobile-hidden menu">
                <!--                    <div class="ui dropdown item">-->
                <!--                        <img class="ui avatar image" src="../../static/images/mio3.jpg" th:src="@{/images/mio3.jpg}">-->
                <!--                        长野原美绪-->
                <!--                        <i class="dropdown icon"></i>-->
                <!--                        <div class="menu">-->
                <!--                            <a href="#" class="item" th:href="@{/admin/user}">管理账号</a>-->
                <!--                            <a href="#" class="item" th:href="@{/admin/logout}">退出登录</a>-->
                <!--                        </div>-->
                <!--                    </div>-->
                <div class="ui dropdown item">
                    <img class="ui avatar image" src="../../static/images/mio3.jpg" th:src="@{${session.user.avatar}}" >

                    <a href="#" class="header" th:text="${session.user.nickname}"> </a>
                    <i class="dropdown icon"></i>
                    <div class="menu">
                        <a href="#" class="item" th:href="@{/admin/user}">管理账号</a>
                        <a href="#" class="item" th:href="@{/admin/logout}">退出登录</a>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <a href="#" class="ui menu toggle m-mobile-show   button">
        展开
        <i class="sidebar  icon m-top-right "></i>
    </a>

</nav>
<!--二级导航-->
<div  th:replace="~{admin/_fragments ::div1}"  class="ui attached pointing menu">
    <div class="ui container">
        <div class="right menu">

            <a href="#" class="item">发布</a>
            <a href="#" class="teal active item">列表</a>
        </div>
    </div>
</div>
<!--    中间内容 -->
<div class="m-padded-tb-large " >

    <div class="ui container">
        <div class="ui top attached segment" th:if="${blog.id != null}">
            <div class="ui mini horizontal link list">
                <div class="item">
                    <img alt=""  class="ui avatar image" src="../static/images/mio1.png"    th:src="@{${blog.user.avatar}}"> <!-- 头像 -->

                    <div class="content">
                        <a href="#" class="header"  th:text="@{${blog.user.nickname}}">长野原美绪</a> <!-- 名字 -->
                    </div>
                </div>
                <div class="item">
                    <i class="calendar icon" ></i> <span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd')}">2024-2-15</span>
                </div> <!-- 时间 -->
                <div class="item">
                    <i class="eye icon"></i> <span th:text="${blog.views} ">55555</span>
                </div> <!-- 观看数 -->

            </div>
        </div>

        <form id="blog-form" action="#" th:object="${blog}" th:action="@{/admin/blogs}" method="post" class="ui form">
            <input type="hidden" name="user.id" th:value="${blog.user.id}" th:if="${blog.id != null}">
            <input type="hidden" name="published" th:value="*{published}">
            <input type="hidden" name="id" th:value="*{id}">
            <div class="required field">
                <div class="ui   left labeled input  ">
                    <div class="ui selection dropdown teal basic compact label">
                        <input type="hidden" value="原创" name="flag" th:value="*{flag}" >
                        <i class="dropdown icon"></i>
                        <div class="text">原创</div>
                        <div class="menu">
                            <div class="item" data-value="原创">
                                原创
                            </div>

                            <div class="item" data-value="转载">
                                转载
                            </div>

                            <div class="item" data-value="翻译">
                                翻译
                            </div>
                        </div>
                    </div>

                    <input type="text" name="title" placeholder="标题,最多50个字节" th:value="${blog.title} " th:attr="maxlength=150">

                </div>
            </div>
            <!--            这个插件我套了好多层就是为了手机也可以用，这里退出全屏会默认回 到第一次打开的页面宽度，所有在pc端打开前 浏览器缩放的很窄的 后小心变小-->
            <div class="ui   container">

                <div class="ui segment">

                    <div class="field">
                        <div id="md-content" class="segment" style="z-index: 1!important">

                    <textarea name="content" placeholder="博客内容"  style="display:none" th:text="*{content}" >


#### Disabled options

- TeX (Based on KaTeX);
- Emoji;
- Task lists;
- HTML tags decode;
- Flowchart and Sequence Diagram;
                    </textarea>
                        </div>
                    </div>
                </div>
            </div>

            <div class="two fields">
                <div class="field">
                    <div class="ui left labeled action input">
                        <label  class="ui compact teal basic label">分类</label>

                        <div class="ui selection fluid dropdown ">

                            <input type="hidden" name="type.id" th:value="*{type}!=null ? *{type.id}">
                            <i class="dropdown icon"></i>
                            <div class="text">分类</div>

                            <div class="menu">

                                <div th:each="type : ${types}" class="item" data-value="1" th:data-value="${type.id}" th:text="${type.name}">错误日志</div>


                            </div>
                        </div>
                    </div>
                </div>
                <div class="field">
                    <div class="ui left labeled action input">
                        <label  class="ui compact teal basic label">标签</label>

                        <div class="ui fluid selection multiple search dropdown ">

                            <input type="hidden" name="tagIds" th:value="*{tagIds}" >
                            <i class="dropdown icon"></i>
                            <div class="text">标签</div>

                            <div class="menu">

                                <div th:each="tag : ${tags}" class="item" data-value="1" th:data-value="${tag.id}" th:text="${tag.name}">java</div>


                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="field">
                <div class="ui left labeled input">
                    <label class="ui teal basic label">首图</label>
                    <input type="text" name="firstPicture" th:value="*{firstPicture}" placeholder="首图引用地址（要求<256字母），输入 1是默认图片-（“没有图片.jpg”）">
                </div>
            </div>

            <div class="required field">
                <textarea name="description" th:text="*{description}" placeholder="博客描述..." maxlength="200"></textarea>
            </div>

            <div class=" inline fields">
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="recommend" name="recommend" checked th:checked="*{recommend}" class="hidden">
                        <label for="recommend" >推荐1</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="shareStatement" name="shareStatement" th:checked="*{shareStatement}" class="hidden">
                        <label for="shareStatement">转载声明</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="appreciate" name="appreciate" class="hidden" th:checked="*{appreciation}!=null ? *{appreciation}">
                        <label for="appreciate" >赞赏</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="comment" name="comment" class="hidden" th:checked="*{commentabled}">
                        <label for="comment" > 评论4</label>
                    </div>
                </div>

            </div>
            <div class="ui error message"></div>

            <div class="ui right aligned container">
                <button type="button" class="ui button" onclick="window.history.go(-1)">返回</button>

                <button type="button" id="save-btn" class="ui secondary button">保存</button>
                <button type="button" id="publish-btn" class="ui teal button">发布</button>
            </div>

        </form>

            <div th:fragment="blogInputReturnNews">
                <div   th:text="${message}" class="alert alert-info"></div>
            </div>
    </div>
</div>

<br>
<br>
<br>
<br>
<br>
<br>


<footer th:replace="~{admin/_fragments ::footer}" class="ui    attached segment m-padded-tb-mini m-shadow-big-up  ">

    <br>
    <br>
    <br>
    <div class="ui center aligned container">
        <div class="ui   divided stackable grid">

            <div class="three wide column">

                <div class="middle aligned">

                    <img src="../../../static/images/mio1.png"
                         class="ui middle aligned round image" alt="" style="width: 150px" th:src="@{/images/mio1.png}">
                </div>


            </div>
            <div class="three wide column ">
                <h4 class ="ui   header" >最新文章</h4>
                <div class="ui red  link list">
                    <div id="newblog-container">
                        <div class="ui   link list" th:fragment="newblogList">
                            <a href="#" th:href="@{/blog/{id}(id=${blog.id})}" target="_blank" class="item black m-text-thin" th:each="blog : ${newblogs}" th:text="${blog.title}">用户故事（User Story）</a>
                            <!--/*-->
                            <!--*/-->
                        </div>
                    </div>
                </div>
            </div>
            <div class="three wide column">
                <h4 class ="ui   header">练习方式</h4>
                <div class="ui black  link list">
                    <a href="#" class="item">yonghuname@github.com</a>
                    <a href="#" class="item">等待填充</a>
                    <a href="#" class="item">等待填充</a>
                </div>
            </div>

            <div class="seven wide column">

                <h4 class ="ui   header">网页介绍</h4>

                <p  class="m-text-thin m-text-spaced m-opacity-mini ">学而不思则罔，思而不学则怠。</p>

            </div>
        </div>

        <!--111111111111111111111111111111-->

        <div class="ui   section divider m-padded-tb-">
        </div> <p class="m-text-thin m-text-spaced m-opacity-mini">All rights reserved  </p>
    </div>
</footer>

</body>


</html>

<script>

    $(document).ready(function() {
        $('.menu.toggle').click(function() {
            $('.m-item').toggleClass('m-mobile-hidden');
        });
    })
    /*
    $(document).ready(function() {
        // 在文档加载完成后执行
        // 选中 textarea 元素，并设置其值为预填充内容
        //只有这样子文本才生效啊

        // $('input[name="title"]').val('');
        // tmd 什么shit semantic  输入框还需要我手动初始化为控制后面的js代码才会见效;

        $('input[name="title"]').val('');

        $('textarea[name="content"]').val('');
    });

     */
    $('.ui.dropdown')
        .dropdown({
            // you can use any ui transition
            // transition: 'drop',
            on:  'hover'
        });


    var contentEditor;
    // 初始化markdown
    $(document).ready(function() {
    contentEditor = editormd("md-content", {
        width: "100%",
        height: 640,
        syncScrolling: "single",
        path: "/static/lib/editormd-master/lib/"
    });
    });


    /*

        $(function() {
            contentEditor = editormd("md-content", {
                width   : "100%",
                height  : 640,
                syncScrolling : "single",
                path    : "/static/lib/editormd-master/lib/"
            //     害死人tmd 。相对路径害死人，还是绝对路径可靠，因为相对路径找不到
            });


        });*/

/*
    function initEditormd() {
        if (typeof jQuery !== 'undefined') {
            // jQuery已经加载，可以初始化Editor.md
            var contentEditor = editormd("md-content", {
                width   : "100%",
                height  : 640,
                syncScrolling : "single",
                path    : "../../static/lib/editormd-master/lib/"
            });
        } else {
            // jQuery尚未加载，设置一个定时器来检查
            setTimeout(initEditormd, 100);
        }
    }

    // 页面加载完成后，执行初始化函数
    $(document).ready(function() {
        initEditormd();
    });
    // 确保jQuery已经加载
*/


    $('.ui.form').form({
        fields : {
            title : {
                identifier: 'title',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入博客标题'
                }]
            },
            content : {
                identifier: 'content',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入博客内容'
                }]
            },
            typeId : {
                identifier: 'type.id',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入博客分类'
                }]
            },
            firstPicture : {
                identifier: 'firstPicture',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入博客首图'
                }]
            },
            description : {
                identifier: 'description',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入博客描述'
                }]
            }

        }
    });

    function saveBlog() {
        $('[name="published"]').val(false);

        $('#blog-form').submit();
        alert("保存请求发送，请保证标题，内容，描述，分类，标签 不为空");

    }
    $('#save-btn').click(function () {
        saveBlog();

    });
    $(document).keydown(function (e) {
        // 检查是否同时按下了 Ctrl 和 S 键
        if (e.ctrlKey && e.shiftKey && e.which === 83) { // 83 是 S 键的键码


            // 执行与点击事件相同的操作
            saveBlog();
        }
    });

    $('#publish-btn').click(function () {
        $('[name="published"]').val(true);
        $('#blog-form').submit();
    });
    document.addEventListener('DOMContentLoaded', function() {
        // 检查是否有消息属性
        if (document.contains(document.getElementById('message'))) {
            // 获取消息内容
            var message = document.getElementById('message').textContent;
            // 显示消息
            alert(message);
            // 阻止页面刷新
            event.preventDefault();
        }
    });

</script>